const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    listData:[],
    forbidData:[],
    answerType:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      answerType: app.globalData.answerType
    })

    let data = app.globalData.formalPapers

    if (app.globalData.answerType == 1) {

      data.map((item)=>{
        if (item.isParticipated == false ){
          item.type = false
          item.tipCOnt = "不可参与"
        } else if (item.startStatus == 2 || item.startStatus == 3) {
          item.type = false
          item.tipCOnt = (item.startStatus == 2 ? '对战将在' + item.startTime + '开始': '已结束') 
        } else if (item.isOpen == false) {
          item.type = false
          let nearestDuration = item.nearestDuration
          let weekIarr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
          item.tipCOnt = '对战将在' + `${weekIarr[nearestDuration.weekDay - 1]} ${nearestDuration.startTime}` + '开始'
        } else {
          item.type = true
        }

        return item
      })

      this.setData({
        forbidData: data.filter(item=> item.type == false)
      })

      this.setData({
        listData: data.filter(item => item.type == true)
      })

    } else {
      this.setData({
        listData: data
      })
    }
    
  },

  setRouter(e) {
    let id = e.currentTarget.dataset.id
    let icon = e.currentTarget.dataset.icon
    
    if (app.globalData.answerType == 1 || app.globalData.answerType == 2) {
      wx.navigateTo({
        url: `/pages/officialExplain/officialExplain?id=${id}&icon=${icon}`
      })
    } else {
      wx.navigateTo({
        url: `/pages/explain/explain?id=${id}&icon=${icon}`
      })
    }
    
  },

  router(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/ranking/ranking?epId=${id}`
    })
  }
})